package com.sleepapp.controller.module;


import cn.dev33.satoken.stp.StpUtil;
import com.sleepapp.annotation.SaAdminCheckLogin;
import com.sleepapp.annotation.SaUserCheckLogin;
import com.sleepapp.service.UserService;
import com.sleepapp.utils.AjaxResult;
import com.sleepapp.vo.LoginBodyVo;
import com.sleepapp.vo.LoginUserResultVo;
import com.sleepapp.vo.UserQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-03-13
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录-用户
     * @param loginBodyVo 登录参数
     * @folder 登录
     */
    @PostMapping("/login")
    public AjaxResult<LoginUserResultVo> login(@RequestBody @Valid LoginBodyVo loginBodyVo) {
        return AjaxResult.success(userService.login(loginBodyVo));
    }

    /**
     * 登录-管理员
     * @param loginBodyVo 登录参数
     * @folder 登录
     */
    @PostMapping("/admin/login")
    public AjaxResult<LoginUserResultVo> adminLogin(@RequestBody @Valid LoginBodyVo loginBodyVo) {
        return AjaxResult.success(userService.adminLogin(loginBodyVo));
    }

    /**
     * 获取积分
     * @folder 积分
     */
    @GetMapping("/points")
    @SaUserCheckLogin
    public AjaxResult<Integer> getPoints() {
        return AjaxResult.success(userService.getPoints());
    }

    /**
     * 获取用户列表
     * @folder 用户
     */
    @GetMapping("/admin/userList")
    @SaAdminCheckLogin
    public AjaxResult<List<UserQueryVo>> userList() {
        return AjaxResult.success(userService.userList());
    }


}

